package servlet.stu;

import bean.HygInfo;
import bean.Manager;
import bean.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDaoImpl;
import utils.JwtUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;



//宿管查询某楼栋的卫生信息
@WebServlet("/stu/getHygOne")
public class StuGetHygOne extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       Integer currentPage= Integer.valueOf(request.getParameter("currentPage"));
        String user_token = request.getHeader("user_token_header");
        Integer buildId = JwtUtils.getStuBuildIdFromToken(user_token,"buildId");
       List<HygInfo> hygInfo = new UserDaoImpl().stuGetHygOne(buildId,currentPage);
        Result result = new Result();
        result.success(hygInfo);
        ObjectMapper objectMapper = new ObjectMapper();
        String str = objectMapper.writeValueAsString(result);
        response.setContentType("application/json;charset=utf8");
        response.getWriter().print(str);
    }
}
